<%@ page language="java" import="java.util.*" pageEncoding="utf-8" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%
    response.setHeader("cache-control","public");
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
            + path + "/";
%>
<!DOCTYPE html>
<html>
<!-- 创建试卷第二步 -->
<head>
    <meta charset="UTF-8">
    <meta name="renderer" content="webkit">
    <title></title>
    <link rel="stylesheet" type="text/css" href="<%=path%>/static/css/bootstrap.css">
    <link rel="stylesheet" type="text/css" href="<%=path%>/static/css/common.css">
    <link rel="stylesheet" type="text/css" href="<%=path%>/static/css/examMng/paperMng.css">
    <!--bootstrap基础引用 start-->
    <script type="text/javascript" src="<%=path%>/static/jstreeview/bootstrap/jquery-3.1.1.min.js"></script>
    <script type="text/javascript" src="<%=path%>/static/js/bootstrap.min.js"></script>
    <!--bootstrap基础引用 end-->
    <!--bootstrap-dialog start-->
    <link rel="stylesheet" type="text/css"
          href="<%=path%>/static/jstreeview/plugins/bootstrap-dialog/bootstrap-dialog.min.css">
    <link rel="stylesheet" type="text/css" href="<%=path%>/static/loading/css/style.css" />
    <script src="<%=path%>/static/loading/js/prefixfree.min.js"></script>
    <script src="<%=path%>/static/loading/js/modernizr.js"></script>
    <script type="text/javascript" src="<%=path%>/static/jstreeview/plugins/bootstrap-dialog/bootstrap-dialog.min.js"></script>
    <!--bootstrap-dialog end-->
    <style>
        .deletebox {
            margin-left: 6px;
            line-height: 175px !important;
        }
        .loader {
            margin-top: 330px !important;
        }
        .popWindow {
            background-color:#9D9D9D;
            width: 100%;
            height: 190%;
            left: 0;
            top: 0;
            filter: alpha(opacity=50);
            opacity: 0.5;
            z-index: 1;
            position: absolute;

        }
        .maskLayer {
            background-color:#000;
            width: 200px;
            height: 30px;
            line-height: 30px;
            left: 50%;
            top: 50%;
            color:#fff;
            z-index: 2;
            position: absolute;
            text-align:center;
        }
    </style>
    <script src="<%=path%>/static/js/respond.js"></script>
    <!--[if !IE]> -->
    <script type="text/javascript">
        window.jQuery || document.write("<script src='<%=path%>/static/js/jquery-2.0.3.min.js'>" + "<" + "/script>");
    </script>
    <!-- <![endif]-->
    <script type="text/javascript">
        window.jQuery || document.write("<script src='<%=path%>/static/js/jquery-1.9.1.min.js'>" + "<" + "/script>");
    </script>
    <script src="<%=path%>/static/js/jquery.selectlist.js"></script>
    <script>
        $(function () {
            $("[data-toggle='tooltip']").tooltip();
        });
    </script>
</head>
<body>
<jsp:include page="../head.jsp" flush="true"/>
<!--body begin-->
<div class="main-container">
    <div class="container body-box">
        <div class="title-top">
            <p>${paper.title}——<span class="rcolor">试卷配置</span></p>
            <a href="javascript:history.go(-1);" class="retun"><i class="glyphicon glyphicon-arrow-left"></i>返回</a>
        </div>
        <div class="paper-content">
            <div class="outcontent">
                <!--步骤 begin-->
                <div class="border_line">
                    <div id="fuelux-wizard" class="row-fluid" data-target="#step-container">
                        <ul class="wizard-steps">
                            <li class="nav_complete">
                                <span class="step"><i class="glyphicon glyphicon-ok"></i></span>
                                <span class="title">试卷基本信息</span>
                            </li>
                            <li class="nav_active">
                                <span class="step">2</span>
                                <span class="title">试卷配置信息</span>
                            </li>
                            <li>
                                <span class="step">3</span>
                                <span class="title">试卷发布</span>
                            </li>
                        </ul>
                    </div>
                </div><!-- /.col -->
                <!--步骤 end-->
                <!--试卷配置信息 begin-->
                <div class="deploy-main">
                    <div class="deploy-top">
                        <a id="addexam" class="btn btn-default add-exam"><i class="glyphicon glyphicon-plus-sign"></i>请选择试题类型</a>
                        <!--<a class="btn btn-default loading">载入模板</a>-->
                    </div>
                    <div id="deployadd" class="deploy-content" style="min-height: 314px;">
                        <!-- 新增页面空数据 -->
                        <c:if test="${flag == 'add' }">
                            <div class="deploybox row">
                                <div class="col-lg-11 col-md-11 line-right">
                                    <div class="input-group input-group-lg deploytype">
                                        <span class="input-group-addon">题目类型</span>
                                        <select name="jinji" id="title_one">
                                            <option value="1">单项选择题</option>
                                            <option value="2">多项选择题</option>
                                            <option value="0">判断题</option>
                                        </select>
                                    </div>
                                    <div class="row">
                                        <div class="col-lg-3 col-md-3 nopadleft">
                                            <div class="input-group input-group-lg deploytype ">
                                                <span class="input-group-addon zjj">数量</span>
                                                <input type="text" class="form-control" maxlength="3"
                                                       onBlur="textBlur(this)" onFocus="textFocus(this)">
                                                <div class="input-group-addon">题</div>
                                            </div>
                                        </div>
                                        <div class="col-lg-3 col-md-3 nopadleft">
                                            <div class="input-group input-group-lg deploytype">
                                                <span class="input-group-addon zjj">分值</span>
                                                <input type="text" class="form-control" maxlength="3"
                                                       onBlur="textBlur(this)" onFocus="textFocus(this)">
                                                <div class="input-group-addon">分/题</div>
                                            </div>
                                        </div>
                                        <div class="col-lg-3 col-md-3 nopadleft">
                                            <div class="input-group input-group-lg deploytype ">
                                                <span class="input-group-addon zjj">难题占比</span>
                                                <input type="text" class="form-control" maxlength="3"
                                                       onBlur="textBlur(this)" onFocus="textFocus(this)">
                                                <div class="input-group-addon">%</div>
                                            </div>
                                        </div>
                                        <div style="float:right" class="col-lg-3 col-md-3 nopadleft">
                                            <div class="input-group input-group-lg deploytype ">
                                                <span class="input-group-addon zjj">易题占比</span>
                                                <input type="text" class="form-control" maxlength="3"
                                                       onBlur="textBlur(this)" onFocus="textFocus(this)">
                                                <div class="input-group-addon">%</div>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                                <div class="col-lg-1 col-md-1">
                                    <div class="deletebox">
                                        <i class="glyphicon glyphicon-trash"></i>
                                        <a>删除</a>
                                    </div>
                                </div>
                            </div>
                        </c:if>
                        <!-- 编辑页面后台返回数据----------------------------单选-------------------------------------------------------------------------- -->
                        <c:forEach items="${singlelist}" var="single" varStatus="status">
                            <div class="deploybox row">
                                <div class="col-lg-11 col-md-11 line-right">
                                    <div class="input-group input-group-lg deploytype">
                                        <input type="text" style="display: none" value="${single.id}"/>
                                        <span class="input-group-addon">题目类型</span>
                                        <select name="jinji">
                                            <option value="1" selected>单项选择题</option>
                                            <option value="2">多项选择题</option>
                                            <option value="3">判断题</option>
                                        </select>
                                    </div>
                                    <div class="row">
                                        <div class="col-lg-3 col-md-3 nopadleft">
                                            <div class="input-group input-group-lg deploytype ">
                                                <span class="input-group-addon zjj">数量</span>
                                                <input type="text" name="count" class="form-control" maxlength="3"
                                                       value="${single.count}" onBlur="textBlur(this)"
                                                       onFocus="textFocus(this)">
                                                <div class="input-group-addon">题</div>
                                            </div>
                                        </div>
                                        <div class="col-lg-3 col-md-3 nopadleft">
                                            <div class="input-group input-group-lg deploytype">
                                                <span class="input-group-addon zjj">分值</span>
                                                <input type="text" name="score" class="form-control" maxlength="3"
                                                       value="${single.score}" onBlur="textBlur(this)"
                                                       onFocus="textFocus(this)">
                                                <div class="input-group-addon">分/题</div>
                                            </div>
                                        </div>
                                        <div class="col-lg-3 col-md-3 nopadleft">
                                            <div class="input-group input-group-lg deploytype ">
                                                <span class="input-group-addon zjj">难题占比</span>
                                                <input type="text" name="rate" class="form-control" maxlength="3"
                                                       value="${single.rate}" onBlur="textBlur(this)"
                                                       onFocus="textFocus(this)">
                                                <div class="input-group-addon">%</div>
                                            </div>
                                        </div>
                                        <div style="float:right" class="col-lg-3 col-md-3 nopadleft">
                                            <div class="input-group input-group-lg deploytype ">
                                                <span class="input-group-addon zjj">易题占比</span>
                                                <input type="text" class="form-control" maxlength="3"
                                                       value="${single.easyrate}" onBlur="textBlur(this)"
                                                       onFocus="textFocus(this)">
                                                <div class="input-group-addon">%</div>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                                <div class="col-lg-1 col-md-1">
                                    <div class="deletebox">
                                        <i class="glyphicon glyphicon-trash"></i>
                                        <a>删除</a>
                                    </div>
                                </div>
                            </div>
                        </c:forEach>
                        <!-- 编辑页面后台返回数据-------------------------多选--------------------------------------------------------------- -->
                        <c:forEach items="${mutilist}" var="muti" varStatus="status">
                            <div class="deploybox row">
                                <div class="col-lg-11 col-md-11 line-right">
                                    <div class="input-group input-group-lg deploytype">
                                        <input type="text" style="display: none" value="${muti.id}"/>
                                        <span class="input-group-addon">题目类型</span>
                                        <select name="jinji">
                                            <option value="1">单项选择题</option>
                                            <option value="2" selected>多项选择题</option>
                                            <option value="3">判断题</option>
                                        </select>
                                    </div>
                                    <div class="row">
                                        <div class="col-lg-3 col-md-3 nopadleft">
                                            <div class="input-group input-group-lg deploytype ">
                                                <span class="input-group-addon zjj">数量</span>
                                                <input type="text" class="form-control" maxlength="3"
                                                       value="${muti.count}" onBlur="textBlur(this)"
                                                       onFocus="textFocus(this)">
                                                <div class="input-group-addon">题</div>
                                            </div>
                                        </div>
                                        <div class="col-lg-3 col-md-3 nopadleft">
                                            <div class="input-group input-group-lg deploytype">
                                                <span class="input-group-addon zjj">分值</span>
                                                <input type="text" class="form-control" maxlength="3"
                                                       value="${muti.score}" onBlur="textBlur(this)"
                                                       onFocus="textFocus(this)">
                                                <div class="input-group-addon">分/题</div>
                                            </div>
                                        </div>
                                        <div class="col-lg-3 col-md-3 nopadleft">
                                            <div class="input-group input-group-lg deploytype ">
                                                <span class="input-group-addon zjj">难题占比</span>
                                                <input type="text" class="form-control" maxlength="3"
                                                       value="${muti.rate}" onBlur="textBlur(this)"
                                                       onFocus="textFocus(this)">
                                                <div class="input-group-addon">%</div>
                                            </div>
                                        </div>
                                        <div style="float:right" class="col-lg-3 col-md-3 nopadleft">
                                            <div class="input-group input-group-lg deploytype ">
                                                <span class="input-group-addon zjj">易题占比</span>
                                                <input type="text" class="form-control" maxlength="3"
                                                       value="${muti.easyrate}" onBlur="textBlur(this)"
                                                       onFocus="textFocus(this)">
                                                <div class="input-group-addon">%</div>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                                <div class="col-lg-1 col-md-1">
                                    <div class="deletebox">
                                        <i class="glyphicon glyphicon-trash"></i>
                                        <a>删除</a>
                                    </div>
                                </div>
                            </div>
                        </c:forEach>
                        <!-- 编辑页面后台返回数据-----------------------判断------------------------------------ -->
                        <c:forEach items="${judgelist}" var="judge" varStatus="status">
                            <div class="deploybox row">
                                <div class="col-lg-11 col-md-11 line-right">
                                    <div class="input-group input-group-lg deploytype">
                                        <input type="text" style="display: none" value="${judge.id}"/>
                                        <span class="input-group-addon">题目类型</span>
                                        <select name="jinji">
                                            <option value="1">单项选择题</option>
                                            <option value="2">多项选择题</option>
                                            <option value="3" selected>判断题</option>
                                        </select>
                                    </div>
                                    <div class="row">
                                        <div class="col-lg-3 col-md-3 nopadleft">
                                            <div class="input-group input-group-lg deploytype ">
                                                <span class="input-group-addon zjj">数量</span>
                                                <input type="text" class="form-control" maxlength="3"
                                                       value="${judge.count}" onBlur="textBlur(this)"
                                                       onFocus="textFocus(this)">
                                                <div class="input-group-addon">题</div>
                                            </div>
                                        </div>
                                        <div class="col-lg-3 col-md-3 nopadleft">
                                            <div class="input-group input-group-lg deploytype">
                                                <span class="input-group-addon zjj">分值</span>
                                                <input type="text" class="form-control" maxlength="3"
                                                       value="${judge.score}" onBlur="textBlur(this)"
                                                       onFocus="textFocus(this)">
                                                <div class="input-group-addon">分/题</div>
                                            </div>
                                        </div>
                                        <div class="col-lg-3 col-md-3 nopadleft">
                                            <div class="input-group input-group-lg deploytype ">
                                                <span class="input-group-addon zjj">难题占比</span>
                                                <input type="text" class="form-control" maxlength="3"
                                                       value="${judge.rate}" onBlur="textBlur(this)"
                                                       onFocus="textFocus(this)">
                                                <div class="input-group-addon">%</div>
                                            </div>
                                        </div>
                                        <div style="float:right" class="col-lg-3 col-md-3 nopadleft">
                                            <div class="input-group input-group-lg deploytype ">
                                                <span class="input-group-addon zjj">易题占比</span>
                                                <input type="text" class="form-control" maxlength="3"
                                                       value="${judge.easyrate}" onBlur="textBlur(this)"
                                                       onFocus="textFocus(this)">
                                                <div class="input-group-addon">%</div>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                                <div class="col-lg-1 col-md-1">
                                    <div class="deletebox">
                                        <i class="glyphicon glyphicon-trash"></i>
                                        <a>删除</a>
                                    </div>
                                </div>
                            </div>
                        </c:forEach>
                    </div>
                    <!--试卷配置信息 end-->
                    <div class="btnbox">
                        <a class="btn btn-success" onclick="precious('/examsys/paper/addOrEdit','${paper.id}')">
                            <i class="glyphicon glyphicon-arrow-left" style="margin-left:0;"></i>上一步</a>
                        <a class="btn btn-info" onclick="next()" style="color: #FFFFFF">下一步
                            <i class="glyphicon glyphicon-arrow-right" style="margin-right:0;"></i></a>

                    </div>
                    <div class="loader">
                        <div class="dot"></div>
                        <div class="dot"></div>
                        <div class="dot"></div>
                        <div class="dot"></div>
                        <div class="dot"></div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<!--body end-->

<!--知识点选择弹窗-->
<div id="close-cn" class="modal fade" tabindex="-1">
    <div class="modal-dialog" style="width:620px">
        <div class="modal-content">
            <!--知识点选择header开始-->
            <div class="modal-header knowsheader">
                <div class="table-header border-top-radius">
                    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">
                        <span class="white">&times;</span>
                    </button>
                    知识点选择：
                </div>
            </div>
            <!--知识点选择header结束-->
            <!--知识点选择body开始-->
            <div class="modal-body knowsbody">
                <div class="text-left knowsbody-nav">请选择知识点：<span></span></div>
                <div class="knowsbody-main">
                    <ul class="knowsmain">
                        <c:forEach items="${list}" var="content" varStatus="status">
                            <li>
                                <div class="onebox">
                                    <input type="text" style="display: none" value="${content.id}"/>
                                    <input type="radio" class="fxkbox" name="zsd_cb"/>
                                    <span>${status.count}. ${content.title }</span>
                                </div>
                                <div class="twobox">
                                    <input type="text" class="srkbox" readonly="readonly"/>
                                    <span>${content.proname }</span>
                                </div>
                                <div class="score">
                                    <span>${content.rankname }</span>
                                </div>
                            </li>
                        </c:forEach>
                    </ul>
                </div>
            </div>
            <!--知识点选择body结束-->
            <!--知识点选择footer开始-->
            <div class="modal-body knowsbody text-center">
                <input class="zsd_qd" type="button" value="确定"/>
                <input class="zsd_qx" type="button" value="取消"/>
            </div>
            <!--知识点选择footer结束-->
        </div>
    </div>
</div>
<div onclick="showDiv()" style="display:block; cursor:pointer">
</div>
<div id="popWindow" class="popWindow" style="display: none; z-index: 999">
</div>
<!--知识点选择弹窗-->


<script type="text/javascript">

    function showDiv() {
        document.getElementById('popWindow').style.display = 'block';
    }
    function closeDiv() {
        document.getElementById('popWindow').style.display = 'none';
    }
    function precious(p, v) {

        var myForm = document.createElement("form");
        myForm.method = "post";
        myForm.action = p;
        var myInput = document.createElement("input");
        myInput.setAttribute("name", "id");  // 为input对象设置name
        myInput.setAttribute("value", v);  // 为input对象设置value
        myForm.appendChild(myInput);
        document.body.appendChild(myForm);
        myForm.submit();
        document.body.removeChild(myForm);  // 提交后移除创建的form
    }

    function next() {
        var len = $('#deployadd').children().length;
        var regular = /^([0-9]*)$/;
        var saveDataAry = [];
        var types = [];
        var scores = 0 ;
        var qsocre ='${paper.score}';
        for (var i = 0; i < len; i++) {
            var id = $("#deployadd").children().eq(i).children().find('div').eq(0).find('input').val();
            var type = $("#deployadd").children().eq(i).children().find('div').eq(0).find('select').val();
            var count = $("#deployadd").children().eq(i).children().find('div').eq(1).children().eq(0).children().find('input').val();
            var score = $("#deployadd").children().eq(i).children().find('div').eq(1).children().eq(1).children().find('input').val();
            var rate = $("#deployadd").children().eq(i).children().find('div').eq(1).children().eq(2).children().find('input').val();
            var easyrate = $("#deployadd").children().eq(i).children().find('div').eq(1).children().eq(3).children().find('input').val();
            types.push(type);
            var data = {
                "id": id,
                "paper_id": '${paper.id}',
                "questiontype_id": type,
                "count": count,
                "score": score,
                "rate": rate,
                "easyrate": easyrate
            };

            scores += parseInt(score)*parseInt(count);
            saveDataAry.push(data);
            var ra = parseInt(rate)+parseInt(easyrate)
            if(ra>100){
                BootstrapDialog.confirm({
                    title: '提示',
                    message: '占比总和不能超过100',
                    size: BootstrapDialog.SIZE_SMALL,
                    type: BootstrapDialog.TYPE_DEFAULT,
                    closable: true,
                    btnCancelLabel: '取消',
                    btnOKLabel: '确定'
                });
                return;
            }
            if (count == "") {
                BootstrapDialog.confirm({
                    title: '提示',
                    message: '数量不能为空',
                    size: BootstrapDialog.SIZE_SMALL,
                    type: BootstrapDialog.TYPE_DEFAULT,
                    closable: true,
                    btnCancelLabel: '取消',
                    btnOKLabel: '确定'
                });
                return;
            }
            if (count <= 0) {
                BootstrapDialog.confirm({
                    title: '提示',
                    message: '数量不能小于0',
                    size: BootstrapDialog.SIZE_SMALL,
                    type: BootstrapDialog.TYPE_DEFAULT,
                    closable: true,
                    btnCancelLabel: '取消',
                    btnOKLabel: '确定'
                });
                return;
            } else {
                if (!regular.test(count)) {
                    BootstrapDialog.confirm({
                        title: '提示',
                        message: '数量输入不符合',
                        size: BootstrapDialog.SIZE_SMALL,
                        type: BootstrapDialog.TYPE_DEFAULT,
                        closable: true,
                        btnCancelLabel: '取消',
                        btnOKLabel: '确定'
                    });
                    return;
                }
            }
            if (score == "") {
                BootstrapDialog.confirm({
                    title: '提示',
                    message: '分值不能为空',
                    size: BootstrapDialog.SIZE_SMALL,
                    type: BootstrapDialog.TYPE_DEFAULT,
                    closable: true,
                    btnCancelLabel: '取消',
                    btnOKLabel: '确定'
                });
                return
            }
            if (score <= 0) {
                BootstrapDialog.confirm({
                    title: '提示',
                    message: '分值不能小于0',
                    size: BootstrapDialog.SIZE_SMALL,
                    type: BootstrapDialog.TYPE_DEFAULT,
                    closable: true,
                    btnCancelLabel: '取消',
                    btnOKLabel: '确定'
                });
                return
            } else {
                if (!regular.test(score)) {
                    BootstrapDialog.confirm({
                        title: '提示',
                        message: '分值输入不符合',
                        size: BootstrapDialog.SIZE_SMALL,
                        type: BootstrapDialog.TYPE_DEFAULT,
                        closable: true,
                        btnCancelLabel: '取消',
                        btnOKLabel: '确定'
                    });
                    return
                }
            }
            if (rate == "") {
                BootstrapDialog.confirm({
                    title: '提示',
                    message: '占比不能为空',
                    size: BootstrapDialog.SIZE_SMALL,
                    type: BootstrapDialog.TYPE_DEFAULT,
                    closable: true,
                    btnCancelLabel: '取消',
                    btnOKLabel: '确定'
                });
                return;
            }
            if (rate <= 0) {
                BootstrapDialog.confirm({
                    title: '提示',
                    message: '占比不能小于0',
                    size: BootstrapDialog.SIZE_SMALL,
                    type: BootstrapDialog.TYPE_DEFAULT,
                    closable: true,
                    btnCancelLabel: '取消',
                    btnOKLabel: '确定'
                });
                return
            }
            if (!regular.test(rate)) {
                BootstrapDialog.confirm({
                    title: '提示',
                    message: '占比输入不符合',
                    size: BootstrapDialog.SIZE_SMALL,
                    type: BootstrapDialog.TYPE_DEFAULT,
                    closable: true,
                    btnCancelLabel: '取消',
                    btnOKLabel: '确定'
                });
                return
            }
            if (rate > 100) {
                BootstrapDialog.confirm({
                    title: '提示',
                    message: '占比不能大于100',
                    size: BootstrapDialog.SIZE_SMALL,
                    type: BootstrapDialog.TYPE_DEFAULT,
                    closable: true,
                    btnCancelLabel: '取消',
                    btnOKLabel: '确定'
                });
                return
            }
        }
        if(scores!=qsocre){
            BootstrapDialog.confirm({
                title: '提示',
                message: '分值与总分不符',
                size: BootstrapDialog.SIZE_SMALL,
                type: BootstrapDialog.TYPE_DEFAULT,
                closable: true,
                btnCancelLabel: '取消',
                btnOKLabel: '确定'
            });
            return;
        }
        //判断是否有重复
        var set = new Set();
        for (var i = 0; i < types.length; i++) {
            set.add(types[i])
        }
        if (types.length != set.size) {
            BootstrapDialog.confirm({
                title: '提示',
                message: '类型重复',
                size: BootstrapDialog.SIZE_SMALL,
                type: BootstrapDialog.TYPE_DEFAULT,
                closable: true,
                btnCancelLabel: '取消',
                btnOKLabel: '确定'
            });
            return;
        }
        $('.loader').show();
        showDiv();
        $.ajax({
            dataType: 'json',
            contentType: "application/json",
            type: 'post',
            url: '<%=basePath%>paper/saveType',
            data: JSON.stringify(saveDataAry),
            success: function (data, status) {
                $('.loader').hide();
                if (data.code == 1) {
                    BootstrapDialog.confirm({
                        title: '提示',
                        message: data.Msg,
                        size: BootstrapDialog.SIZE_SMALL,
                        type: BootstrapDialog.TYPE_DEFAULT,
                        closable: true,
                        btnCancelLabel: '取消',
                        btnOKLabel: '确定'
                    });
                } else {
                    var myForm = document.createElement("form");
                    myForm.method = "post";
                    myForm.action = "<%=path%>/paper/issue";
                    var myInput = document.createElement("input");
                    myInput.setAttribute("name", "paperid");  // 为input对象设置name
                    myInput.setAttribute("value", '${paper.id}');  // 为input对象设置value
                    myForm.appendChild(myInput);
                    document.body.appendChild(myForm);
                    myForm.submit();
                    document.body.removeChild(myForm);  // 提交后移除创建的form
                }
            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {
                BootstrapDialog.confirm({
                    title: '提示',
                    message: '系统错误',
                    size: BootstrapDialog.SIZE_SMALL,
                    type: BootstrapDialog.TYPE_DEFAULT,
                    closable: true,
                    btnCancelLabel: '取消',
                    btnOKLabel: '确定'
                });
            }
        });
    }

    //paper-add-deploy.htm添加试题类型按钮
    $(document).ready(function () {

        $('.loader').hide();
        // 试卷管理
        if (${role eq 'master'}) {
            $('#topMain').children().eq(0).addClass('active'); // 追加样式;
            $('#topMain').children().eq(0).children().attr('href', '#');
        } else if (${role eq 'trainee'}) {
            $('#topMain').children().eq(0).addClass('active'); // 追加样式;
            $('#topMain').children().eq(0).children().attr('href', '#');
        } else {
            $('#topMain').children().eq(4).addClass('active'); // 追加样式;
        }

        var nums = $(".knowsmain li").length;
        for (var i = 0; i < nums; i++) {
            $(".knowsmain").children().eq(i).find(".twobox").find("input").val(0);
        }
        $('#addexam').click(function () {
            var tipcon =
                '<div class="deploybox row">' +
                '<div class="col-lg-11 col-md-11 line-right">' +
                '<div class="input-group input-group-lg deploytype">' +
                '<span class="input-group-addon">题目类型</span>' +
                '<select name="jinji" >' +
                '<option value="1">单项选择题</option>' +
                '<option value="2">多项选择题</option>' +
                '<option value="3">判断题</option>' +
                '</select>' +
                '</div>' +
                '<div class="row">' +
                '<div class="col-lg-3 col-md-3 nopadleft">' +
                '<div class="input-group input-group-lg deploytype ">' +
                '<span class="input-group-addon zjj">数量</span>' +
                '<input type="text" class="form-control" maxlength="3">' +
                '<div class="input-group-addon">题</div>' +
                '</div>' +
                '</div>' +
                '<div class="col-lg-3 col-md-3 nopadleft">' +
                '<div class="input-group input-group-lg deploytype">' +
                '<span class="input-group-addon zjj">分值</span>' +
                '<input type="text" class="form-control" maxlength="3">' +
                '<div class="input-group-addon">分/题</div>' +
                '</div>' +
                '</div>' +
                '<div class="col-lg-3 col-md-3 nopadleft">' +
                '<div class="input-group input-group-lg deploytype ">' +
                '<span class="input-group-addon zjj">难题占比</span>' +
                '<input type="text" class="form-control" maxlength="3" >' +
                '<div class="input-group-addon">%</div>' +
                '</div>' +
                '</div>' +
                '<div style="float:right" class="col-lg-3 col-md-3 nopadleft">' +
                '<div class="input-group input-group-lg deploytype ">' +
                '<span class="input-group-addon zjj">易题占比</span>' +
                '<input type="text" class="form-control" maxlength="3">' +
                '<div class="input-group-addon">%</div>' +
                '</div>' +
                '</div>' +
                '</div>' +
                '</div>' +
                '<div class="col-lg-1 col-md-1">' +
                '<div class="deletebox">' +
                '<i class="glyphicon glyphicon-trash"></i>' +
                '<a>删除</a>' +
                '</div>' +
                '</div>' +
                '</div>';
            var len = $('#deployadd').children().length;
            if (len < 3) {
                $('#deployadd').append(tipcon);
            }
            // 删除表单
            $('.deletebox a').click(function () {
                len = $('#deployadd').children().length;
                if (len > 1) {
                    $(this).parent().parent().parent().remove();
                }
            });
        });
        // 删除表单
        $('.deletebox a').click(function () {
            var len = $('.deploybox').length;
            if (len > 1) {
                $(this).parent().parent().parent().remove();
            }
        });
        var val = "";
        var title = "";
        //当勾选时 checkbox
        //题库章节知识点设置 暂时没用着
        $(".knowsmain li .onebox .fxkbox").click(function () {
            var val = $(this).prev().val();
            var title = $(this).next().text();
            var obj = $(this).parent().parent().parent().parent().parent().parent().parent().parent().parent().next();
            obj.val(title);
        });

        //当点击弹窗确定按钮时，隐藏弹窗并把选择的数据放在知识点input中
        $(".zsd_qd").click(function () {
            $(this).parent().val();
            $('#close-cn').modal('hide');
        });
        $(".zsd_qx").click(function () {
            $('#close-cn').modal('hide');
        });
    });

    //文本框默认提示文字
    function textFocus(el) {
        if (el.defaultValue == el.value) {
            el.value = '';
            el.style.color = '#333';
        }
    }

    function textBlur(el) {
        score = $("#deployadd").children().eq(0).find(".line-right").children().eq(1).children().eq(1).children().eq(0).children().eq(1).val();
        scorenums = $("#deployadd").children().eq(0).find(".line-right").children().eq(1).children().eq(0).children().eq(0).children().eq(1).val();
        percent = $("#deployadd").children().eq(0).find(".line-right").children().eq(2).children().eq().children().eq(0).children().eq(1).val();
        var reg = /^\d+$/;// 这里是 正则表达式
        var val = el.value
        if (val == "") {
            /*alert("11111不能为空")*/
        }
        if (reg.test(scorenums) != true) {
            //$("#deployadd").children().eq(0).find(".line-right").children().eq(1).children().eq(0).children().eq(0).children().eq(1).val("请输入所选试题类型总数").css("color","red");
        } else {
            //$("#deployadd").children().eq(0).find(".line-right").children().eq(1).children().eq(0).children().eq(0).children().eq(1).css("color","#222");
        }
        if (reg.test(score) != true) {
            //$("#deployadd").children().eq(0).find(".line-right").children().eq(1).children().eq(1).children().eq(0).children().eq(1).val("请输入该类型试题分值").css("color","red");
        } else {
            //$("#deployadd").children().eq(0).find(".line-right").children().eq(1).children().eq(1).children().eq(0).children().eq(1).css("color","222");
        }
        if (reg.test(percent) != true) {
            //$("#deployadd").children().eq(0).find(".line-right").children().eq(1).children().eq(2).children().eq(0).children().eq(1).val("请输入难题所占比例").css("color","red");
        } else {
            //$("#deployadd").children().eq(0).find(".line-right").children().eq(1).children().eq(2).children().eq(0).children().eq(1).css("color","222");
        }
    }
    //监听 浏览器的返回事件
    $(document).ready(function(e) {
        var counter = 0;
        if (window.history && window.history.pushState) {
            $(window).on('popstate', function () {
                window.history.pushState('forward', null, '#');
                window.history.forward(1);
                //填写逻辑
                var paperid = '${paper.id}';
                var myForm = document.createElement("form");
                myForm.method = "post";
                myForm.action = "<%=path%>/paper/addOrEdit";
                var myInput = document.createElement("input");
                myInput.setAttribute("name", "id");  // 为input对象设置name
                myInput.setAttribute("value", paperid);  // 为input对象设置value
                myForm.appendChild(myInput);
                document.body.appendChild(myForm);
                myForm.submit();
                document.body.removeChild(myForm);  // 提交后移除创建的form
            });
        }
        window.history.pushState('forward', null, '#'); //在IE中必须得有这两行
        window.history.forward(1);
    });

</script>
</div>
</body>
</html>
